import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_photo.dart';
import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';

/// description: 隐患排查相关页面底部弹窗 选择器
/// @Param [title] 标题
/// @Param [hintText] 提示字段

class CustomHazardInvestigation extends StatefulWidget {
  const CustomHazardInvestigation({
    required this.title,
    required this.hintText,
    required this.onConfirm,
    super.key,
  });

  final String title;
  final String hintText;
  final Function(HazardCallbackBean bean) onConfirm;

  @override
  State<CustomHazardInvestigation> createState() => _CustomHazardInvestigationState();
}

class _CustomHazardInvestigationState extends State<CustomHazardInvestigation> {
  HazardCallbackBean callbackBean = HazardCallbackBean(content: '', pictureList: []);

  @override
  void initState() {
    super.initState();
  }

  /// 弹窗内容
  Widget _getDialogContentView() {
    return Container(
      alignment: Alignment.topLeft,
      padding: EdgeInsets.fromLTRB(30.w, 20.w, 30.w, 0),
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              widget.title,
              style: TextStyle(
                fontSize: 18.sp,
                fontWeight: FontWeight.w500,
                color: const Color(0xff262626),
              ),
            ),
            AppGaps.vGap10,
            CustomHighInputPage(
              isShowDivider: false,
              title: '${widget.hintText}：',
              isRequired: false,
              hintText: '请输入${widget.hintText}...',
              onCallBack: (value) {
                callbackBean.content = value;
              },
            ),
            AppGaps.vGap6,
            CustomPickerPhoto(
              title: '拍照:',
              imagesList: callbackBean.pictureList,
              maxCount: 3,
              titleTextStyle: TextStyle(
                color: const Color(0xFF262F38),
                fontSize: 14.sp,
                fontWeight: FontWeight.w400,
              ),
              callback: (List<String> path) {
                callbackBean.pictureList = path;
              },
            ),
          ],
        ),
      ),
    );
  }

  /// 提交
  void complete() {
    if (callbackBean.content.isEmpty) {
      AppToast.showWarning('请输入${widget.hintText}!');
      return;
    }
    if (callbackBean.pictureList.isEmpty && widget.title != '驳回') {
      AppToast.showWarning('请上传拍照!');
      return;
    }
    widget.onConfirm(callbackBean);
    Get.back();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          gradient: const LinearGradient(
              //渐变位置
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              //渐变颜色[始点颜色, 结束颜色]
              colors: [Color(0xffE7EAFF), Color(0xffFFFFFF), Color(0xffFFFFFF), Color(0xffFFFFFF)]),
          borderRadius: BorderRadius.only(topLeft: Radius.circular(10.w), topRight: Radius.circular(10.w))),
      child: Column(
        children: [
          Expanded(child: _getDialogContentView()),
          Container(
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
                  offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
                  blurRadius: 10.0, // 阴影的模糊半径
                  spreadRadius: 2.0, // 阴影的扩散半径
                ),
              ],
            ),
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Container(
                    height: 40.w,
                    width: 120.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: const Color(0xffffffff),
                        border: Border.all(color: const Color(0xff5C6DFF), width: 1.w),
                        borderRadius: BorderRadius.all(Radius.circular(20.w))),
                    child: Text(
                      '取消',
                      style: TextStyle(
                        fontSize: 18.sp,
                        color: const Color(0xff5C6DFF),
                      ),
                    )).clickOnce(Get.back),
                AppGaps.hGap20,
                Expanded(
                  child: Container(
                      height: 40.w,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(color: const Color(0xff5C6DFF), borderRadius: BorderRadius.all(Radius.circular(20.w))),
                      child: Text(
                        '确认',
                        style: TextStyle(
                          fontSize: 18.sp,
                          color: Colors.white,
                        ),
                      )).clickOnce(complete),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class HazardCallbackBean {
  HazardCallbackBean({required this.content, required this.pictureList});

  /// 输入内容
  String content;

  /// 选择图片
  List<String> pictureList;
}
